-
Notifications
You must be signed in to change notification settings - Fork 361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize json encoding #2481
Optimize json encoding #2481
Conversation
203f4a0
to
0213551
Compare
Hey @philippthun, Thanks for the PR! Oj seems actively maintained so that sounds good, one thing I did notice is that this PR introduces another gem |
0213551
to
e5076b3
Compare
Hi @JenGoldstrich! Thanks for your review. The |
@philippthun Are you planning to make a PR to capi-release to add the new config property? |
@tjvman I'm not sure about this. Ideally using the optimized json encoder should become the default. It might make sense to add the config option also to CAPI and then enable it on some foundations to see if everything is really compatible. And in the end this option could then be removed again... |
@philippthun Yeah, that makes sense to me for this kind of performance optimization thing - make it an opt-in at first, then make it the default. How long (time or number of releases) do you think we should leave it as optional I don't see a way to enable the |
@tjvman I've create a CAPI PR (cloudfoundry/capi-release#208) that exposes the I guess we would enable it stepwise on our foundations, so the property might stay there for a few months. |
- Parse JSON response instead of searching for a substring. - Decode 'X-Broker-Api-Originating-Identity' header value and check contained 'user_id' instead of comparing two base64 encoded strings. - Add missing '}' to JSON string.
- Add 'oj' gem. - Introduce optional 'use_optimized_json_encoder' config property. - If 'use_optimized_json_encoder' is true, use Oj (optimized for Rails) and omit 'as_json' calls for all Presenters.
e5076b3
to
293c9c2
Compare
I think this is a great change and should provide API-wide performance improvements! |
While looking at the performance of the /v3/security_groups endpoints (PR #2475), I also checked how much the database queries were contributing to the overall response times. As this was not much after optimizing the queries, I started to look into the topic of JSON serialization. I found several comments and benchmarks claiming that Oj is the fastest JSON encoder/decoder; so I started with a small PoC.
I've managed to completely switch to Oj and run all unit tests successfully. For comparison of JSON outputs before and after the change, I use the jd command-line tool.
I decided to introduce an optional config property (
use_optimized_json_encoder
). I've enabled it on a foundation and successfully run CATS.Here are some results of locally executed performance tests (
X-Runtime
header):* each security group is assigned to 500 spaces
I have reviewed the contributing guide
I have viewed, signed, and submitted the Contributor License Agreement
I have made this pull request to the
main
branchI have run all the unit tests using
bundle exec rake
I have run CF Acceptance Tests *
* We cannot run all CATS on our foundations as we do not enable all CF features, but all the executed tests were successful: